<template>
    <view class="page-setting-index">
        <view class="mx-4">
            <u-form ref="form2" label-width="360rpx">
                <u-form-item label="主页不展示待参加活动">
                        <template v-slot:right>
                            <u-switch v-model="form.hidePendingActivities" size="40" active-color="#67E5C2" @change="editUserInfo"></u-switch>
                        </template>
                </u-form-item>
                <u-form-item label="主页不展示已参加活动">
                        <template v-slot:right>
                            <u-switch v-model="form.hideParticipatedActivities" size="40" active-color="#67E5C2" @change="editUserInfo"></u-switch>
                        </template>
                </u-form-item>
                <u-form-item label="主页不展示已发起活动">
                        <template v-slot:right>
                            <u-switch v-model="form.hideInitiatedActivities" size="40" active-color="#67E5C2" @change="editUserInfo"></u-switch>
                        </template>
                </u-form-item>
                <u-form-item label="主页不展示收藏内容" :border-bottom="true">
                        <template v-slot:right>
                            <u-switch v-model="form.hideFavorites" size="40" active-color="#67E5C2" @change="editUserInfo"></u-switch>
                        </template>
                </u-form-item>
            </u-form>
        </view>
        <view class="m-4">
            <!-- <u-button class="btn-default" @click="loginOut" shape="square">退出登录</u-button> -->
            <view class="align-center c-grey9 p-4" @click="loginOut">退出登录</view>
        </view>
        
    </view>
</template>
<script setup lang="ts">
import { onLoad, onShow } from '@dcloudio/uni-app'
import { useAppStore } from '@/stores/app';
const {proxy} = getCurrentInstance() as ComponentInternalInstance;
const appStore = useAppStore();
const form = reactive({
    userId: null,
    hideInitiatedActivities: false,
    hideFavorites: false,
    hideParticipatedActivities: false,
    hidePendingActivities: false,
});
const editUserInfo = () => {
    let params = {
        userId: form.userId,
        hideInitiatedActivities: form.hideInitiatedActivities ? '1' : '0',
        hideFavorites: form.hideFavorites ? '1' : '0',
        hideParticipatedActivities: form.hideParticipatedActivities ? '1' : '0',
        hidePendingActivities: form.hidePendingActivities ? '1' : '0',
    };
    appStore.editUserInfo(params).then(res => {
        getUserInfo();
    })
};
const getUserInfo = () => {
    appStore.getUserInfo().then(res => {
        form.userId = res.userId;
        form.hideInitiatedActivities = res.hideInitiatedActivities == '1';
        form.hideFavorites = res.hideFavorites == '1';
        form.hideParticipatedActivities = res.hideParticipatedActivities == '1';
        form.hidePendingActivities = res.hidePendingActivities == '1';
    })
}
const loginOut = () => {
    uni.showModal({
        title: '提示',
        content: '确定要退出登录？',
        success: res => {
            if(res.confirm){
                uni.clearStorage();
                uni.reLaunch({
                    url: '/pages/login/index'
                })
            }
        }
    })
    
};
onShow(() => {
    getUserInfo();
})
</script>
<style>
page{height:100%;background:#fff;}
</style>